package the.broccoli.ac.service.impl;

import org.springframework.util.CollectionUtils;
import the.broccoli.ac.entity.App;
import the.broccoli.ac.mapper.AppMapper;
import the.broccoli.ac.service.IAppService;
import org.wisteria.framework.web.mvc.service.AbstractSuperService;
import org.springframework.stereotype.Service;
import the.broccoli.ac.vo.AppVO;
import org.wisteria.framework.web.mvc.dto.TreeDTO;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 应用 服务实现类
 * </p>
 *
 * @author lei.liu
 * @since 2020-04-07
 */
@Service
public class AppServiceImpl extends AbstractSuperService<AppMapper, App> implements IAppService {

    /**
     * 获取所有应用树
     *
     * @return
     */
    @Override
    public List<TreeDTO> getTree() {
        List<App> appList = this.listByCondition(new AppVO());
        if (CollectionUtils.isEmpty(appList)) {
            return null;
        }

        List<TreeDTO> treeList = new ArrayList<>();
        TreeDTO treeDTO = null;
        for (App app : appList) {
            treeDTO = new TreeDTO();
            treeDTO.setId(app.getAppId()+"");
            treeDTO.setTitle(app.getAppName());
            treeList.add(treeDTO);
        }
        return treeList;
    }
}
